package find.prj.lib;

import java.util.ArrayList;

public class FileSearchFucktory {
	
	private FileSearchFucktory() {
	}

	/** Returns instance of Searcher, depends whether if you need serial search or threaded one
	 * 
	 * @param rootPaths - array of paths to search in
	 * @return returns ParallelFileSearch if all rootPaths from different logical disks or SerialFileSeach if not
	 */
	public static Searcher newInstance (String[] rootPaths) {
		if ( isPathsFromDiffDisks(rootPaths) )
			return new ParallelFileSearch();
		else
			return new SerialFileSearch();
	}
	
	/** Checks if rootPaths contains paths from different logical disks
	 * 
	 * @param rootPaths - string array containing paths
	 * @return true if all paths from different logical disks, 
	 * false - if not
	 */
	private static boolean isPathsFromDiffDisks(String[] rootPaths)
	{
		boolean result = true;
		ArrayList<String> disks = new ArrayList<String>();
		for (String rootPath : rootPaths) {
			if (disks.contains(rootPath.trim().substring(1, 1).toLowerCase()))
				return false;
			disks.add(rootPath.trim().substring(1, 1).toLowerCase());
		}
		return result;
	}
}
